<?php
defined ( 'BASEPATH' ) or exit ( 'No direct script access allowed' );
class Shelve_model extends CI_Model {
	public function __construct() {
		parent::__construct ();
	}
	/*
	 * 添加商品下架记录
	 */
	public function create($shelve) {
		$this->db->insert ( 't_shelve', $shelve );
		return $this->db->insert_id ();
	}
	/*
	 * 根据分页信息返回商品下架记录
	 */
	public function find_all_shelves($show,$per_page,$offset){
		$this->db->select('t_shelve.id,t_shelve.productid,t_shelve.name,t_shelve.date,t_product.show');
		$this->db->from('t_shelve');
		$this->db->join('t_product', 't_product.id = t_shelve.productid','left');
		if($show==1){
			$this->db->where('t_product.show=0');
		}
		$this->db->limit($per_page, $offset);
		$this->db->order_by("date", "desc");
		$query = $this->db->get();
		return $query->result_array();
	}
	/*
	 * 返回商品下架记录总数
	 */
	public function count_shelves($show){
		$this->db->from('t_shelve');
		$this->db->join('t_product', 't_product.id = t_shelve.productid','left');
		if($show==1){
			$this->db->where('t_product.show=0');
		}
		$query = $this->db->get();
		return $query->num_rows();
	}
}